import React, { forwardRef, useImperativeHandle } from "react";


function Son(props,ref) {

  console.log("子组件的ref",ref);//这个ref就是子组件的ref【在父组件定义的sonRef】

  const str="hello";

  // 对外暴露
  useImperativeHandle(ref,()=>({
    msg:str,
    fn(){
      console.log("fn");
    }
  }))
 

  return (
    <div>
      <h1>子组件</h1>
    </div>
  );
}

export default forwardRef(Son);
